//// include DevIL for image loading
//#include <IL/il.h>
//// assimp include files. These three are usually needed.
//#include <assimp.hpp>	
//#include <aiPostProcess.h>
//#include <aiScene.h>
//// include GLEW to access OpenGL 3.3 functions
//#include <GL/glew.h>
//// GLUT is the toolkit to interface with the OS
//#include <GL/freeglut.h>
//#include "HelloOpenGLCommon.h"
//
//#include "Technique.h"
//#include "Pipeline.h"
//#include "Camera.h"
//#include "Texture.h"
//#include "Node2D.h"
//V3F_C4B_T2F_Quad* quad = NULL;
//Technique* pEffect = new Technique();
//Camera* pCamera = NULL;
//Texture* pTexture = NULL;
//Node2D* pNode = NULL;
//Node2D* root_node = NULL;
//#define WINDOW_WIDTH  320
//#define WINDOW_HEIGHT 320
//float rotation = 0;
//float alpha = 255;
//int init()					 
//{
//	if (!pEffect->onInit("default.vert","default.frag"))
//	{
//		return false;
//	}
//
//	Vector3f Pos(0.0f, 0.0f, 1.0f);
//	Vector3f Target(0.0f, 0.0f, -1.0f);
//	Vector3f Up(0.0, 1.0f, 0.0f);
//	pCamera = new Camera(WINDOW_WIDTH, WINDOW_HEIGHT, Pos, Target, Up);
//
//	// Load the textures
//	pTexture = new Texture(GL_TEXTURE_2D,"a.png");
//	if (!pTexture->Load())
//	{
//		printf("can't load texture!\r\n");
//		return false;
//	}
//	pNode = new Node2D();
//	root_node = new Node2D();
//
//	/*Node2D* child1 = new Node2D();
//	child1->setName("a1");
//	root_node->addChild(child1);
//	Node2D* child2 = new Node2D();
//	child2->setName("a2");
//	root_node->addChild(child2);
//	Node2D* child3 = new Node2D();
//	child3->setName("a3");
//	root_node->addChild(child3);
//	Node2D* child4 = new Node2D();
//	child4->setName("a4");
//	root_node->addChild(child4);
//
//	root_node->setChildIndex(child3,-1000);
//
//	for (int i = 0;i<root_node->count();i++)
//	{
//		Node2D* pNode = root_node->getChildAt(i);
//		printf("=============%s\r\n",pNode->getName().c_str());
//	}*/
//	//HelloOpenGLCommon::genRectQuad(&quad);
//	
//	glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );
//	return true;
//}
//void processSpecialKeys(int key, int x, int y)
//{
//	pCamera->OnKeyboard(key);
//}
//void processPassiveMouseButtons(int x, int y)
//{
//	//pCamera->OnMouse(x, y);
//}
//void processMouseButtons(int button, int state, int xx, int yy) 
//{
//}
//void processKeys(unsigned char key, int xx, int yy) 
//{
//}
//void processMouseMotion(int xx, int yy)
//{
//}
//void mouseWheel(int wheel, int direction, int x, int y)
//{
//}
//void changeSize(int width, int height) 
//{
//	// Compute aspect ratio of the new window
//	if (height == 0) height = 1;                // To prevent divide by 0
//	GLfloat aspect = (GLfloat)width / (GLfloat)height;
//
//	// Set the viewport to cover the new window
//	glViewport(0, 0, width, height);
//
//	// Set the aspect ratio of the clipping area to match the viewport
//	glMatrixMode(GL_PROJECTION);  // To operate on the Projection matrix
//	glLoadIdentity();             // Reset the projection matrix
//	gluOrtho2D(0, width, height, 0);
//	//gluOrtho2D(-1, 1, -1, 1);
//	//if (width >= height) {
//	//	// aspect >= 1, set the height from -1 to 1, with larger width
//	//	gluOrtho2D(-1.0 * aspect, 1.0 * aspect, -1.0, 1.0);
//	//} else {
//	//	// aspect < 1, set the width to -1 to 1, with larger height
//	//	gluOrtho2D(-1.0, 1.0, -1.0 / aspect, 1.0 / aspect);
//	//}
//
//	/*D3DXMATRIX tmp;
//	D3DXMatrixScaling(&matProj, 1.0f, -1.0f, 1.0f);
//	D3DXMatrixTranslation(&tmp, -0.5f, height+0.5f, 0.0f);
//	D3DXMatrixMultiply(&matProj, &matProj, &tmp);
//	D3DXMatrixOrthoOffCenterLH(&tmp, 0, (float)width, 0, (float)height, 0.0f, 1.0f);
//	D3DXMatrixMultiply(&matProj, &matProj, &tmp);*/
//
//
//}
//void doTransfrom(Vertex3F& vertices,CCAffineTransform transform)
//{
//	CCPoint point(vertices.x,vertices.y);
//	point = CCPointApplyAffineTransform(point,transform);
//	vertices.x = point.x;
//	vertices.y = point.y;
//}
//void renderScene4(void) 
//{
//	glClear ( GL_COLOR_BUFFER_BIT );
//	glEnable(GL_TEXTURE_2D);
//	if (pTexture != NULL)
//	{
//		pTexture->Bind(GL_TEXTURE0);
//	}
//	// Define shapes enclosed within a pair of glBegin and glEnd
//	glBegin(GL_QUADS);              // Each set of 4 vertices form a quad
//	float x = WINDOW_WIDTH/2;
//	float y = WINDOW_HEIGHT/2;
//	x = 10;
//	y = 10;
//	float w = 128;
//	float h = 128;
//	unsigned int direction = 1;
//	glColor4f(1.0f, 0.0f, 0.0f,1);
//	glTexCoord2f(0, 1);
//	glVertex2f(x, direction * y);     // Define vertices in counter-clockwise (CCW) order
//
//	glColor4f(0.0f, 1.0f, 0.0f,1);
//	glTexCoord2f(1, 1);
//	glVertex2f(x + w,direction *  y);     //  so that the normal (front-face) is facing you
//
//	glColor4f(0.0f, 0.0f, 1.0f,0.0f);
//	glTexCoord2f(1, 0);
//	glVertex2f(x + w, direction * (y + h));
//
//	glColor4f(0.0f, 0.0f, 0.0f,0.0f);
//	glTexCoord2f(0, 0);
//	glVertex2f(x, direction * (y + h));
//	glEnd();
//	glFlush();  // Render now
//	glutSwapBuffers();
//}
//
//void renderScene(void) 
//{
//	
//	// Clear the color buffer
//	glClear ( GL_COLOR_BUFFER_BIT );
//	glViewport(0, 0, WINDOW_WIDTH,WINDOW_HEIGHT);
//	// Use the program object
//	pEffect->enable();
//
//	pCamera->OnRender();
//	Pipeline p;
//	double dist = sqrt(1 / 3.0);
//	Vector3f CameraPos(dist, dist, dist);
//	Vector3f CameraTarget(0.0f, 0.0f, 0.0f);
//	Vector3f CameraUp(0.0f, 1.0f, 0.0f);
//	p.SetCamera(CameraPos, CameraTarget, CameraUp);
//	pEffect->setWorldMatrix(p.GetWVPTrans());
//	//glEnable(GL_BLEND);        
//	//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//
//	root_node->removeAllChildren();
//
//	Node2D* parent = new Node2D();
//	root_node->addChild(parent);
//	//root_node->mPos.x = 100;
//	//root_node->mAlpha = 120;
//	Node2D* child = new Node2D();
//	parent->addChild(child);
//	rotation+=0.0001;
//	if (rotation > 360)
//	{
//		rotation = 0;
//	}
//	
//	//p.SetPerspectiveProj(60.0f, WINDOW_WIDTH, WINDOW_HEIGHT, 1.0f, 100.0f);
//	parent->mPos.x = 100;
//	parent->mPos.y = 100;
//	//parent->mRotation = rotation;
//	
//	//child->mRotation = 90;
//	//child->mAnchorPoint.x = 0.5;
//	//child->mAnchorPoint.y = 0.5;
//	child->mPos.x = 0;
//	child->mPos.y = 0;
//	child->mAlpha = 255;
//	//child->mScaleX = 2;
//	//child->mScaleY = 2;
//	child->mContentSize.width = 32;
//	child->mContentSize.height = 32;
//	child->setTexture(pTexture);
//	child->update(WINDOW_WIDTH,WINDOW_HEIGHT);
//	child->draw(pEffect);
//
//	glutSwapBuffers();
//}
//void renderScene3(void) 
//{
//	//glClear ( GL_COLOR_BUFFER_BIT );
//	//// Define shapes enclosed within a pair of glBegin and glEnd
//	//glBegin(GL_QUADS);              // Each set of 4 vertices form a quad
//	//glColor3f(1.0f, 0.0f, 0.0f); // Red
//	//glVertex2f(0.0f, 0.0f);     // Define vertices in counter-clockwise (CCW) order
//	//glVertex2f(0.5f, 0.0f);     //  so that the normal (front-face) is facing you
//	//glVertex2f(0.5f, 0.5f);
//	//glVertex2f(0.0f, 0.5f);
//	//glEnd();
//	//glFlush();  // Render now
//	/*float w = 64.0f;
//	float scale = WINDOW_WIDTH / WINDOW_WIDTH;
//	HelloOpenGLCommon::genRectQuad3(&quad,0.5);
//
//	if (quad == NULL)
//	{
//		return;
//	}*/
//	// Set the viewportw
//	glViewport ( 0, 0, WINDOW_WIDTH,WINDOW_HEIGHT );
//	// Clear the color buffer
//	glClear ( GL_COLOR_BUFFER_BIT );
//	// Use the program object
//	pEffect->enable();
//
//	pCamera->OnRender();
//	Pipeline p;
//
//	pNode->mPos.x = 0;
//	pNode->mPos.y = 0;
//	//pNode->mScaleX = 0.5;
//	rotation+= 0.0001;
//	if (rotation > 3.14*2)
//	{
//		rotation = 0;
//	}
//	
//	//pNode->mRotation = rotation;
//	//pNode->mSkewX = 0.5;
//	pNode->mContentSize.width = 32;
//	pNode->mContentSize.height = 32;
//	pNode->setTexture(pTexture);
//	pNode->update(WINDOW_WIDTH,WINDOW_HEIGHT);
//	pNode->draw(pEffect);
//	//Matrix4f worldMatrix;
//	//CCAffineTransform transform = pNode->transform();
//	//CGAffineToGL2(&transform,&worldMatrix);
//	//printf("worldMatrix\n");
//	//worldMatrix.Print();
//	//doTransfrom(quad->tl.vertices,transform);
//	//doTransfrom(quad->tr.vertices,transform);
//	//doTransfrom(quad->bl.vertices,transform);
//	//doTransfrom(quad->br.vertices,transform);
//
//	//
//	////pEffect->setWorldMatrix(worldMatrix);
//	////p.SetCamera(pCamera->GetPos(), pCamera->GetTarget(), pCamera->GetUp());
//	////p.SetPerspectiveProj(60.0f, WINDOW_WIDTH, WINDOW_HEIGHT, 0.0f, 50.0f);
//	////pEffect->SetWVP(p.GetWVPTrans());
//
//	//long offset = (long)quad;
//	//// vertex
//	//int diff = offsetof( V3F_C4B_T2F, vertices);
//	//glVertexAttribPointer(pEffect->getAttribLocation("a_position"), 3, GL_FLOAT, GL_FALSE, sizeof(quad->bl), (void*) (offset + diff));
//
//	//// texCoods
//	//diff = offsetof( V3F_C4B_T2F, texCoords);
//	//glVertexAttribPointer(pEffect->getAttribLocation("a_texCoord"), 2, GL_FLOAT, GL_FALSE, sizeof(quad->bl), (void*)(offset + diff));
//
//	//// color
//	//diff = offsetof( V3F_C4B_T2F, colors);
//	//glVertexAttribPointer(pEffect->getAttribLocation("a_color"), 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(quad->bl), (void*)(offset + diff));
//
//	//glEnableVertexAttribArray ( pEffect->getAttribLocation("a_position") );
//	//glEnableVertexAttribArray ( pEffect->getAttribLocation("a_texCoord") );
//	//glEnableVertexAttribArray ( pEffect->getAttribLocation("a_color") );
//
//	//pTexture->Bind(GL_TEXTURE0);
//	//// Set the base map sampler to texture unit to 0
//	//glUniform1i ( pEffect->getUniformLocation("s_baseMap"), 0 );
//	//glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
//
//	glutSwapBuffers();
//}
//
//void renderScene2()
//{
//	if (pEffect == NULL)
//	{
//		return;
//	}
//	// Clear the color buffer
//	glClear ( GL_COLOR_BUFFER_BIT );
//	glViewport(0, 0, WINDOW_WIDTH,WINDOW_HEIGHT);
//	glMatrixMode(GL_PROJECTION);  // To operate on the Projection matrix
//	glLoadIdentity();             // Reset the projection matrix
//	gluOrtho2D(-1, 1,-1, 1);
//	glMatrixMode(GL_MODELVIEW);
//	glLoadIdentity();
//	GLfloat* vertices = NULL;
//	GLushort* indices = NULL;
//	HelloOpenGLCommon::genRect(&vertices,&indices);
//	pEffect->enable();
//	// Load the vertex position
//	glVertexAttribPointer ( pEffect->getAttribLocation("a_position"), 3, GL_FLOAT, 
//		GL_FALSE, 5 * sizeof(GLfloat), vertices );
//	// Load the texture coordinate
//	glVertexAttribPointer ( pEffect->getAttribLocation("a_texCoord"), 2, GL_FLOAT,
//		GL_FALSE, 5 * sizeof(GLfloat), &vertices[3] );
//
//	glEnableVertexAttribArray ( pEffect->getAttribLocation("a_position") );
//	glEnableVertexAttribArray ( pEffect->getAttribLocation("a_texCoord") );
//
//	if (pTexture != NULL)
//	{
//		pTexture->Bind(GL_TEXTURE0);
//		// Set the base map sampler to texture unit to 0
//		glUniform1i ( pEffect->getUniformLocation("s_baseMap"), 0 );
//	}
//	glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices );
//	glutSwapBuffers();
//}
//void shutDown ()
//{
//	// Delete texture object
//	delete pTexture;
//	// Delete program object
//	delete pEffect;
//}
//int _tmain(int argc, char **argv)
//{
//	//test();
//	//  GLUT initialization
//	glutInit(&argc, argv);
//
//	glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGBA|GLUT_MULTISAMPLE);
//
//	glutInitContextVersion (2, 0);
//	glutInitContextFlags (GLUT_COMPATIBILITY_PROFILE );
//
//	glutInitWindowPosition(100,100);
//	glutInitWindowSize(WINDOW_WIDTH,WINDOW_HEIGHT);
//	glutCreateWindow("Hello Textrue!");
//
//
//	//  Callback Registration
//	glutDisplayFunc(renderScene);
//	//glutReshapeFunc(changeSize);
//	glutIdleFunc(renderScene);
//
//	glutSpecialFunc(processSpecialKeys);
//	glutPassiveMotionFunc(processPassiveMouseButtons);
//
//	//	Mouse and Keyboard Callbacks
//	glutKeyboardFunc(processKeys);
//	glutMouseFunc(processMouseButtons);
//	glutMotionFunc(processMouseMotion);
//
//	glutMouseWheelFunc ( mouseWheel ) ;
//
//	//	Init GLEW
//	//glewExperimental = GL_TRUE;
//	glewInit();
//	if (glewIsSupported("GL_VERSION_2_0"))
//		printf("Ready for OpenGL 2.0\n");
//	else {
//		printf("OpenGL 2.0 not supported\n");
//		exit(1);
//	}
//
//	//  Init the app (load model and textures) and OpenGL
//	if (!init())
//		printf("Could not Load the Model\n");
//
//	printf ("Vendor: %s\n", glGetString (GL_VENDOR));
//	printf ("Renderer: %s\n", glGetString (GL_RENDERER));
//	printf ("Version: %s\n", glGetString (GL_VERSION));
//	printf ("GLSL: %s\n", glGetString (GL_SHADING_LANGUAGE_VERSION));
//
//
//	// return from main loop
//	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
//
//	//  GLUT main loop
//	glutMainLoop();
//	shutDown();
//}
//
